<template>
  <div id="app">
    <transition :name="slideName">
      <router-view />
    </transition>
  </div>
</template>

<script>
export default {
  data() {
    return {
      slideName: ''
    }
  },
  watch: {
    $route(to, from) {
      if (to.meta.index > from.meta.index) {
        // 父 -> 子
        this.slideName = 'slide-left'
      } else {
        this.slideName = 'slide-right'
      }
    }
  }
}
</script>

<style>
.slide-left-leave-active,
.slide-left-enter-active,
.slide-right-leave-active,
.slide-right-enter-active {
  transition: all 0.5s;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}
/* 子页面 */
.slide-right-leave,
/* 父页面 */
.slide-right-enter-to {
  transform: translateX(0);
}
/* 子页面 */
.slide-right-leave-to {
  transform: translateX(100%);
}
/* 父页面 */
.slide-right-enter {
  transform: translateX(-100%);
}

/* 父页面 */
.slide-left-leave,
/* 子页面 */
.slide-left-enter-to {
  transform: translateX(0);
}
/* 父页面 */
.slide-left-leave-to {
  transform: translateX(-100%);
}

/* 子页面 */
.slide-left-enter {
  transform: translateX(100%);
}
html,
body {
  padding: 0;
  margin: 0;
  width: 100%;
  height: 100%;
}

h1 {
  margin: 0;
}

#app {
  height: 100%;
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
}

nav {
  padding: 30px;
}

nav a {
  font-weight: bold;
  color: #2c3e50;
}

nav a.router-link-exact-active {
  color: #42b983;
}
</style>
